<?php
require_once ('./resource/SDK/XingeApp.php');
/**
 * Class ApiService
 */

class ApiService extends BaseService
{

    private static $self = NULL;

    static public function instance()
    {
        if (self::$self == NULL) {
            self::$self = new self;
        }

        return self::$self;
    }

    private $status_msgs        =  NULL;
    private $mAdmin             =  NULL;
    private $mAds               =  NULL;
    private $mLog               =  NULL;
    private $mProject           =  NULL;
    private $mInvestRecord      =  NULL;
    private $mTicketRecord      =  NULL;
    private $mRechargeRecord    =  NULL;
    private $mWithdrawRecord    =  NULL;
    private $mBankManage        =  NULL;
    private $mUser              =  NULL;
    private $mNews              =  NULL;
    private $mAbutPartner       =  NULL;
    private $mAbutTeam          =  NULL;
    private $mAbutRecruit       =  NULL;
    private $mCompany           =  NULL;
    private $mUserExtend        =  NULL;
    private $mInvitie           =  NULL;
    private $mMessage           =  NULL;
    private $mLookUser          =  NULL;
    private $mLockLogin         =  NULL;
    private $mBusinessPic       =  NULL;
    private $mExperRecord       =  NULL;
    private $mExperScale        =  NULL;
    private $mLookWithdraw      =  NULL;
    private $mLineChart         =  NULL;
    private $mVideo             =  NULL;
    private $mBankCard          =  NULL;
    private $mFactCompany       =  NULL;
    private $mDeposit           =  NULL;
    private $mVersion           = NULL;





    public function __construct()
    {
        $this->status_msgs              = ProfessionErrorCodeEnum::$status_msgs;
        $this->mAdmin             =   new Involved_AdminModel();
        $this->mAds               =   new Involved_AdsModel();
        $this->mLog               =   new Involved_LogModel();
        $this->mProject           =   new Involved_ProjectModel();
        $this->mInvestRecord      =   new Involved_InvestRecordModel();
        $this->mTicketRecord      =   new Involved_TicketRecordModel();
        $this->mRechargeRecord    =   new Involved_RechargeRecordModel();
        $this->mWithdrawRecord    =   new Involved_WithdrawRecordModel();
        $this->mBankManage        =   new Involved_BankManageModel();
        $this->mUser              =   new Involved_UserModel();
        $this->mNews              =   new Involved_NewsModel();
        $this->mAbutPartner       =   new Involved_AbutPartnerModel();
        $this->mAbutTeam          =   new Involved_AbutTeamModel();
        $this->mAbutRecruit       =   new Involved_AbutRecruitModel();
        $this->mCompany           =   new Involved_CompanyModel();
        $this->mUserExtend        =   new Involved_UserExtendModel();
        $this->mInvitie           =   new Involved_InvitieModel();
        $this->mMessage           =   new Involved_MessageModel();
        $this->mLookUser          =   new Involved_LookUserModel();
        $this->mLockLogin         =   new Involved_LockLoginModel();
        $this->mBusinessPic       =   new Involved_BusinessPicModel();
        $this->mExperRecord       =   new Involved_ExperRecordModel();
        $this->mExperScale        =   new Involved_ExperScaleModel();
        $this->mLookWithdraw      =   new Involved_LookWithdrawModel();
        $this->mLineChart         =   new Involved_LineChartModel();
        $this->mVideo             =   new Involved_VideoModel();
        $this->mBankCard          =   new Involved_BankCardModel();
        $this->mBankCard          =   new Involved_BankCardModel();
        $this->mFactCompany       =   new Involved_FactCompanyModel();
        $this->mDeposit           =   new Involved_DepositModel();
        $this->mVersion           = new Involved_VersionModel();


    }

    /**
     * 随机数
     * @param $length
     * @return string
     */
    function random_str($length)
    {
        //生成一个包含 大写英文字母, 小写英文字母, 数字 的数组
        $arr = array_merge(range(0, 9), range('a', 'z'));
        $str = '';
        $arr_len = count($arr);
        for ($i = 0; $i < $length; $i++)
        {
            $rand = mt_rand(0, $arr_len-1);
            $str.=$arr[$rand];
        }

        return $str;
    }

    /**
     * 信鸽推送
     * @param $user_id
     * @param $title
     * @param $content
     * @author lzhp
     */
    public function XG($user_id,$title,$content)
    {
        $message_count = $this->mMessage->MessageCount($user_id);
        $account= "yangpiaotong_".$user_id;
        $xinge1 = XingeApp::PushAccountIos(2200208674,"253d5e8fd27f9934c15574d68fd2cfcd",$content ,$account ,XingeApp::IOSENV_PROD,$message_count+1);
        $xinge2 = XingeApp::PushAccountAndroid(2100203846,"20004ff8eb9c07cdd9a6b57ce4acde1e",$title, $content,$account);
        if($xinge1['ret_code']==0||$xinge2['ret_code']==0){
            $aData = [
                'title'              =>     $title,
                'content'            =>     $content,
                'status'             =>     '2',
                'created'            =>     time(),
                'user_id'            =>     $user_id,
            ];
            $this->mMessage->insert($aData);
        }
    }
    /**
     * 参数验证
     * @param $obj
     * @param $arr
     * @author alice
     * @date 2016-1-13
     * @return bool
     * @return bool
     */
    public function  checkProperties($obj, $arr)
    {
        if (empty($arr)) return true;
        $obj = (array)$obj;

        foreach ($arr as $v) {
            if (is_null($obj[$v])) {
                return false;
            }
        }
        return true;
    }

    /**
     * 获取首页数据
     * @param $paramObj
     * @author  xf
     * @date    2016-6-24
     * @return array
     * @throws Exception
     */
    public function GetIndexData($paramObj)
    {
        $list = $this->mProject->YptProjectList($paramObj->page);
        if($list==[]){
            return $list;
        }
        $company_name = $this->Relevance($list,'company_name'); //获取公司名称数组
        $companylist = $this->mCompany->CompanyList($company_name);//获取公司列表
        $company = $this->VelToKey($companylist,'company_name');
        //获取项目已投资金额
        $all_prpject_id = $this->Relevance($list,'project_id'); //获取项目名称数组
        $already_money = $this->mInvestRecord->AlreadyMoney($all_prpject_id);//根据ID获取项目投资金额
        $already = $this->VelToKey($already_money,'project_id');
        $time3 = strtotime(date('Y-m-d H:i:s', time()));//获得当前时间戳
        foreach($list as &$v){
            if(isset($company)){
                $v->rank = $company[$v->company_name]->rank;
                $v->times=$time3-$v->end_time;
                if(empty($already[$v->project_id])){
                    $v->percentage = "0";
                    $v->already_money   =$v->project_scale;
                }else{

                    $v->percentage = number_format($already[$v->project_id]->money/$v->project_scale*100,2);
                    $v->already_money=$v->project_scale-$already[$v->project_id]->money;

                }
            }
        }
        return $list;

    }

    /**
     * 获取央票通数据
     * @param $paramObj
     * @author  xf
     * @date    2016-6-24
     * @return array
     * @throws Exception
     */
    public function GetyptData($paramObj)
    {
        $list = $this->mProject->YptProjectData($paramObj->page);
        if($list==[]){
            return $list;
        }
        $company_name = $this->Relevance($list,'company_name'); //获取公司名称数组
        $companylist = $this->mCompany->CompanyList($company_name);//获取公司列表
        $company = $this->VelToKey($companylist,'company_name');
        //获取项目已投资金额
        $all_prpject_id = $this->Relevance($list,'project_id'); //获取项目名称数组
        $already_money = $this->mInvestRecord->AlreadyMoney($all_prpject_id);//根据ID获取项目投资金额
        $already = $this->VelToKey($already_money,'project_id');
        $time3 = strtotime(date('Y-m-d H:i:s', time()));//获得当前时间戳
        foreach($list as &$v){
            if(isset($company)){
                $v->rank = $company[$v->company_name]->rank;
                $v->times=$time3-$v->end_time;
                if(empty($already[$v->project_id])){
                    $v->percentage = "0";
                    $v->already_money   =$v->project_scale;
                }else{

                    $v->percentage = number_format($already[$v->project_id]->money/$v->project_scale*100,2);
                    $v->already_money=$v->project_scale-$already[$v->project_id]->money;

                }
            }
        }
        return $list;

    }

    /**
     * 获取上市通数据
     * @param $paramObj
     * @author  xf
     * @date    2016-6-24
     * @return array
     * @throws Exception
     */
    public function GetsstData($paramObj)
    {
        $list = $this->mProject->SstProjectData($paramObj->page);
        if($list==[]){
            return $list;
        }
        $company_name = $this->Relevance($list,'company_name'); //获取公司名称数组
        $companylist = $this->mCompany->CompanyList($company_name);//获取公司列表
        $company = $this->VelToKey($companylist,'company_name');
        //获取项目已投资金额
        $all_prpject_id = $this->Relevance($list,'project_id'); //获取项目名称数组
        $already_money = $this->mInvestRecord->AlreadyMoney($all_prpject_id);//根据ID获取项目投资金额
        $already = $this->VelToKey($already_money,'project_id');
        $time3 = strtotime(date('Y-m-d H:i:s', time()));//获得当前时间戳
        foreach($list as &$v){
            if(isset($company)){

                $v->times=$time3-$v->end_time;
                if(empty($already[$v->project_id])){
                    $v->percentage = "0";
                    $v->already_money   =$v->project_scale;
                }else{

                    $v->percentage = number_format($already[$v->project_id]->money/$v->project_scale*100,2);
                    $v->already_money=$v->project_scale-$already[$v->project_id]->money;

                }
            }
        }
        return $list;

    }


    /**
     * 获取央票通详情页
     * @param $paramObj
     * @author  xf
     * @date    2016-6-27
     * @return array
     * @throws Exception
     */
    public function yptDdetailsData($project_id)
    {
        $user_id = session_get(UserEnum::USER_INFO_USER_ID);
        $list = $this->mProject->YptProjectdetailsData($project_id);
        $company_name = $this->Relevance($list,'company_name'); //获取公司名称数组
        $companylist = $this->mCompany->CompanyList($company_name);//获取公司列表
        $company = $this->VelToKey($companylist,'company_name');
        //获取项目已投资金额
        $all_prpject_id = $this->Relevance($list,'project_id'); //获取项目ID称数组
        $already_money = $this->mInvestRecord->AlreadyMoney($all_prpject_id);//根据ID获取项目投资金额
        $already = $this->VelToKey($already_money,'project_id');
        // return  $already;
        //获取合作伙伴信息
        $all_prpject_id = $this->Relevance($list,'partner_id'); //获取项目ID称数组
        $partnerlist = $this->mAbutPartner->GetPartnerId($all_prpject_id);//根据ID获取项目合作商信息
        $partner = $this->VelToKey($partnerlist,'partner_id');
        //获取保理商信息
        $fact_company = $this->Relevance($list,'factoring_company'); //获取保理商信息名称
        $factionlist = $this->mFactCompany->Factcompany($fact_company);//获取保理商信息列表
        $faction    = $this->VelToKey($factionlist,'f_company_name');
        $time3 = strtotime(date('Y-m-d H:i:s', time()));//获得当前时间戳
        foreach($list as &$v){
            if(isset($company) and !empty($partner)){
                $v->rank = $company[$v->company_name]->rank;
                $v->moneyw  =$v->project_scale/10000;
                $v->plate = $company[$v->company_name]->plate;
                $v->brief = $company[$v->company_name]->brief;
                $v->partner_id = $partner[$v->partner_id]->partner_name;
                $v->psdk = "http://www.yangpiaotong.com/resource/SDK/投资服务协议及应收账款转让协议（平台）.doc";
                $v->imageyang=array( $v->image1, $v->image2);
                $v->imgbao=array($v->img1,$v->img2,$v->img3);
                $v->company_brief   =$faction[$v->factoring_company]->company_brief;
                $v->assess_opinion  =$faction[$v->factoring_company]->assess_opinion;
                $v->times=$time3-$v->end_time;
                if(!empty($user_id)){
                    $getuserid=$this->mUserExtend->UserExtendone($user_id);
                    $v->user_balances=$getuserid->user_balance;
                }else{
                    $v->user_balances="0";
                }
                if(empty($already[$v->project_id])){
                    $v->percentage = "0";
                    $v->already_money   =$v->project_scale;
                }else{
                    $v->percentage = number_format($already[$v->project_id]->money/$v->project_scale*100,2);
                    $v->already_money=$v->project_scale-$already[$v->project_id]->money;
                    if($time3-$v->end_time>0||$v->already_money=='0'){
                        $v->expire=1;
                    }else{
                        $v->expire=0;
                    }


                }
            }
        }
        return $list;

    }

    /**
     *现金劵是否过期修改statue状态
     */
    public function vouchersta()
    {
        $user_id = session_get(UserEnum::USER_INFO_USER_ID);
        if(!empty($user_id)){
            $voucher = $this->mUser->voucherstatue($user_id);
            foreach ($voucher as $key => $v) {
                $data = date('Y-m-d', $v->time);
                $time3 = strtotime(date('Y-m-d', time()));//获得当前时间戳 $v->datetime
                $time2 = strtotime(date('Y-m-d', strtotime("$data+ 30 day")));//到期时间
                if ($time2 >= $time3) {
                    $aData = array(
                        'statue' => 0,
                    );
                    $this->mInvitie->update($aData, ['time' => $v->time]);
                } else {
                    $aData = array(
                        'statue' => 1,
                    );
                    $this->mInvitie->update($aData, ['time' => $v->time]);
                }
            }
            return $voucher;
        }else{
            $voucher='';
            return $voucher;
        }

    }


    //现金劵
    public function voucher($paramObj)
    {
        $user_id = session_get(UserEnum::USER_INFO_USER_ID);
        if(empty($user_id)){
            throw new Exception('用户未登录！', ErrorCodeEnum::STATUS_ERROR_NOT_LOGIN);
        }
        $voucher=$this->mUser->voucher($user_id,$paramObj->page);
        foreach ($voucher as &$v) {
            $data = date('Y-m-d', $v->time);// 1467169713
            $v->time = strtotime(date('Y-m-d', strtotime("$data+ $v->datetime day")));//到期时间
        }
        return $voucher;
    }


    /**
     *体验金
     */
    public function experience()
    {
        $user_id = session_get(UserEnum::USER_INFO_USER_ID);
        if(empty($user_id)){
            throw new Exception('用户未登录！', ErrorCodeEnum::STATUS_ERROR_NOT_LOGIN);
        }
        $experdata= $this->mUser->experience($user_id);
        //体验金是否过期，查看staue状态
        $data = date('Y-m-d', $experdata->time);
        $time3 = strtotime(date('Y-m-d', time()));//获得当前时间戳 $v->datetime
        $time2 = strtotime(date('Y-m-d', strtotime("$data+ 30 day")));//到期时间
        if ($time2 >= $time3) {
            if ($experdata->statue!=2) {
                $aData = array(
                    'statue' => 0,
                );
                $this->mExperScale->update($aData, ['time' =>  $experdata->time]);
            }
        }else{
            if ($experdata->statue!=2) {
                $aData = array(
                    'statue' => 1,
                );
                $this->mExperScale->update($aData, ['time' =>  $experdata->time]);
            }

        }
        return $experdata;

    }
    /**
     *体验金收益完成金额
     */
    public function experiencemoney()
    {
        $user_id = session_get(UserEnum::USER_INFO_USER_ID);
        if(empty($user_id)){
            throw new Exception('用户未登录！', ErrorCodeEnum::STATUS_ERROR_NOT_LOGIN);
        }
        $experiencemoney = $this->mUser->experiencemoney($user_id);
        // return $experiencemoney;
        if(!empty($experiencemoney)){
            $money  = $experiencemoney[0]->exper_money;//金额
            $nums   = $experiencemoney[0]->exper_nums;//期限
            $time   = $experiencemoney[0]->exper_time;//投资时间
            $annua  = $experiencemoney[0]->exper_annua / 100;//年利率
            if(empty($money)||empty($nums)||empty($time)||empty($annua)){
                throw new Exception($this->error_msg[ProfessionErrorCodeEnum::STATUS_ERROR_PARAMS_MUST],
                    ProfessionErrorCodeEnum::STATUS_ERROR_PARAMS_MUST);
            }
            $shouyi = $money * $nums * $annua;
            $time3  =strtotime(date("Y-m-d H:i:s",time()));//获得当前时间戳
            $time2  =strtotime(date("Y-m-d H:i:s",$time+60*60*24));//到期时间
            if ($time2 <= $time3){
                $year=date("Y");//判断年份
                if(($year%4==0)&&($year%100!=0)||($year%400==0)){
                    $gains=round($shouyi/366,2);
                    return $gains;
                }else{
                    $gains=round($shouyi/365,2);
                    return  $gains;
                }
            }else{
                return 0;
            }
        }else{

            return 0;
        }

    }


    /**
     *投资收益算法
     */
    public  function GetdetailsData($paramObj){
        $asda=session_get(UserEnum::USER_INFO_USER_ID);
        if(empty($asda)){
            throw new Exception('用户未登录！', ErrorCodeEnum::STATUS_ERROR_NOT_LOGIN);
        }
        if (!empty($asda)){
            if(empty($paramObj->project_id )||empty($paramObj->type)||empty($paramObj->money)){
                throw new Exception($this->error_msg[ProfessionErrorCodeEnum::STATUS_ERROR_PARAMS_MUST],
                    ProfessionErrorCodeEnum::STATUS_ERROR_PARAMS_MUST);
            }
            $project_id =$paramObj->project_id;
            $type       =$paramObj->type;
            $list = $this->mProject->GetdetailsData($project_id,$type);
            $money  = $paramObj->money;//金额
            $nums   = $list[0]->limit;//期限
            $time   = $list[0]->start_time;//投资时间
            $annua  = $list[0]->yield_rate / 100;//年利率
            // if (empty($money)||empty($nums)||empty($time)||empty($annua)) {return "参数错误！！！";}
            $shouyi = $money * $nums * $annua;
            $time3  =strtotime(date("Y-m-d H:i:s",time()));//获得当前时间戳
            $time2  =strtotime(date("Y-m-d H:i:s",$time+60*60*24));//到期时间
            $year=date("Y");//判断年份
            if(($year%4==0)&&($year%100!=0)||($year%400==0)){
                $gains=round($shouyi/366,2);
            }else{
                $gains=round($shouyi/365,2);
            }
            //return  $gains;
            //是否有可用现金券
            $voucher=$this->mUser->vouchers($asda,$money);
            if($voucher>=1){
                $voucher=1;
            }else{
                $voucher=0;
            }
            $array=array(
                'voucher' =>$voucher,
                'gains' =>$gains,
            );
            return $array;

        }
    }



    //邀请人列表
    public function Reward($paramObj)
    {
        $user_id = session_get(UserEnum::USER_INFO_USER_ID);
        if(empty($user_id)){
            throw new Exception('用户未登录！', ErrorCodeEnum::STATUS_ERROR_NOT_LOGIN);
        }
        return $this->mUser->Reward($user_id,$paramObj->page);


    }

    /**
     * ajax投资支付密码
     * @return mixed
     */
    public function AjaxProjectPay($paramObj)
    {
        $asda=session_get(UserEnum::USER_INFO_SESSION_KEY);
        $UserInfoPwd=$this->mUser->ApiGetUserInfoPwd($asda['user_id']);
        if(empty($asda['user_id'])){
            throw new Exception('用户未登录！', ErrorCodeEnum::STATUS_ERROR_NOT_LOGIN);
        }
         if (empty($paramObj->pwd)){
           throw new Exception('密码不能为空', ProfessionErrorCodeEnum::ERROR_PASSWORD_NULL);
          }
        if(empty($paramObj->moneys)||empty($paramObj->type)||empty($paramObj->project_id)){
            throw new Exception($this->error_msg[ProfessionErrorCodeEnum::STATUS_ERROR_PARAMS_MUST],
                ProfessionErrorCodeEnum::STATUS_ERROR_PARAMS_MUST);
        }
        $pay_num    = $UserInfoPwd->pay_num;//随机数
        $selectsid    =$paramObj->select;//优惠券id
        $selectdata=$this->mUser->UserwardOne($selectsid);
        if(!empty($selectdata)){
            $select =$selectdata->reward;//优惠券
        }else{
            $select =0;//优惠券
        }
        $moneys     =$paramObj->moneys;//支付金额
        $pwd        =md5(md5($paramObj->pwd).$pay_num);
        $UserE      =$this->mUserExtend->UserExtendone($asda['user_id']);//获取总金额
        $amount     =$UserE->user_balance;//账户总金额
        if(!empty($amount)){
            $in_amo =($amount-$moneys)+$select;
        }else{
            throw new Exception('余额不足', ErrorCodeEnum::STATUS_ERROR_NOT_MONEY);
            $in_amo=0;
        }

        $LookUsers  =$this->mLookUser->lockuser($asda['user_id']);//获取人是不是本冻结
        $lockusertime  =$this->mLookUser->lockusertime($asda['user_id']);//获取人是不是本冻结
        if(!empty($lockusertime)){
            $timelock = $lockusertime->locktime;//获得当前时间戳 $v->datetime
            $timelock2 = $timelock+60*60*12;//到期时间
            if($timelock2 < time()){
                $LookUseraaaa=$this->mLookUser->delete(['user_id'=>$asda['user_id']]);
            }
        }
        if(!empty($LookUsers)){//如果被冻结，看是否到解锁时间
            $LookUsersa  =$this->mLookUser->lockuserone($asda['user_id']);
            if(time()<$LookUsersa->locktime){
                // $mess['code'] = '2';
                // $mess['mess'] = '对不起，您的账户已被锁定,请于'.date('Y-m-d H:i:s',$LookUsersa->locktime).'后尝试登录！';
                // return $mess;
                throw new Exception('对不起，您的账户已被锁定,请于'.date('Y-m-d H:i:s',$LookUsersa->locktime).'后尝试登录！', ErrorCodeEnum::STATUS_ERROR_PASSWORD_WRONG);
            }else{
                $LookUseraaaa=$this->mLookUser->delete(['user_id'=>$asda['user_id']]);
            }
        }
        if ($pwd==$UserInfoPwd->pay_pwd){
            $aData= array(
                'user_balance'  =>$in_amo,//投资完的资金
            );
           // return  $aData;
            //收益金额
            $GetdetailsData=$this->mProject->GetdetailsDataone($paramObj->project_id,$paramObj->type);
            $yield_money=$this->mUser->Algorithm($moneys,$GetdetailsData->limit,$GetdetailsData->yield_rate);
            $rdata=array(
                'project_id'    =>$paramObj->project_id,
                'type'          =>$paramObj->type,
                'user_id'       =>$asda['user_id'],
                'project_name'  =>$GetdetailsData->project_name ,
                'invest_money'  =>$moneys,
                'yield_rate'    =>$GetdetailsData->yield_rate ,
                'limit'         =>$GetdetailsData->limit ,
                'invest_time'   =>time(),
                'yield_money'   =>round($yield_money,2),
                'status'        =>2
            );
            // 删除优惠券
            if(!empty($select)){
                $Invitiesa =$this->mInvitie->delete(['t_id'=>$selectsid,'u_id'=>$asda['user_id']]);
            }
            // return $Invitiesa;
            $dataextend= $this->mUserExtend->update($aData,['user_id' =>$asda['user_id']]);
            $dataRecord= $this->mInvestRecord->insert($rdata);//投资记录表
            //资产日历
            $time3 = date('Y-m-d', time());//获得当前时间戳 $v->datetime
            $time2 = strtotime(date('Y-m-d', strtotime("$time3 + $GetdetailsData->limit day")));//到期时间
            $countmoney=$this->mUser->CountAlgorithm($moneys,$GetdetailsData->limit,$GetdetailsData->yield_rate);
            $countmoney=round($countmoney,2);
            //收益金额
            $profit_money= $countmoney-$moneys;
            $cart=array(
                'year'          =>  date('Y', $time2),
                'month'         =>  date('n', $time2),
                'day'           =>  date('j', $time2),
                'wait_money'    =>  $countmoney,
                'profit_money'  =>  $profit_money,
                'time'          =>  $time2,
                'user_id'       =>  $asda['user_id'] ,
            );
            $LineChart  =$this->mLineChart->linechartpay($asda['user_id'],date('Y', $time2),date('n', $time2),date('j', $time2));
            if(!empty($LineChart)){
                $LineChartone  =$this->mLineChart->linechartone($asda['user_id'],date('Y', $time2),date('n', $time2),date('j', $time2));
                $countmoneys= $countmoney+$LineChartone->wait_money;
                $profimoneys= $profit_money+$LineChartone->profit_money;
                $cart=array(
                    'wait_money'    =>  $countmoneys,
                    'profit_money'  =>  $profimoneys,
                    'time'          =>  $time2,
                    'user_id'       =>  $asda['user_id']
                );
                $this->mLineChart->update($cart,['id' =>$LineChartone->id]);

            }else{
                $this->mLineChart->insert($cart);//柱状图
            }
            $cartdang=array(
                'year'          =>  date('Y', time()),
                'month'         =>  date('n', time()),
                'day'           =>  date('j', time()),
                'money'         =>  $moneys,
                'user_id'       =>  $asda['user_id'] ,
            );
            $LineChartd  =$this->mLineChart->linechartpay($asda['user_id'],date('Y', time()),date('n', time()),date('j', time()));
            if(!empty($LineChartd)){
                $LineChartone  =$this->mLineChart->linechartone($asda['user_id'],date('Y', time()),date('n', time()),date('j', time()));
                $moneydang= $moneys+$LineChartone->money;
                $cartup=array(
                    'money'         =>  $moneydang,
                    'user_id'       =>  $asda['user_id']
                );

                $this->mLineChart->update($cartup,['id' =>$LineChartone->id]);

            }else{
                $this->mLineChart->insert($cartdang);//柱状图
            }

            if (!empty($dataRecord)&&!empty($dataextend)) {
                $this->XG($asda['user_id'],'投资成功','您已经成功投资'.$GetdetailsData->project_name.'项目,投资金额'.$moneys.'元');
                return 1;
            }

        }else{
            $LookUsersa  =$this->mLookUser->lockuserone($asda['user_id']);//获取本人有没有输入

            if(!empty($LookUsersa->number)){
                $count = $LookUsersa->number;
                if($count<= 4){
                    $count++;
                    $logins=$count;
                    $array=array(
                        'number'    =>$logins,
                        'user_id'   =>$asda['user_id'],
                        'locktime'  =>time(),
                        'ip'        =>$_SERVER['REMOTE_ADDR'],
                    );
                    if ($count<1) {
                        $LookUserd= $this->mLookUser->insert($array);
                    }
                    if ($count>0&&$count<=4) {
                        $LookUserd= $this->mLookUser->update($array,['id' => $LookUsersa->id]);
                    }

                }
                if($count == 5){
                    $data4['number'] = $count;
                    $data4['user_id'] = $asda['user_id'];
                    $data4['locktime'] = time()+60*30;
                    $data4['ip'] = $_SERVER['REMOTE_ADDR'];
                    $LookUserd= $this->mLookUser->update($data4,['id' => $LookUsersa->id]);
                    if (!empty($LookUserd)) {
                        //return('{"success":false,"msg":"您已经连续5次输入错误密码，账户被锁定30分钟"}');
                        // $mess['code'] = '2';
                        // $mess['mess'] = '您已经连续5次输入错误密码，账户被锁定30分钟';
                        // return $mess;
                        throw new Exception('您已经连续5次输入错误密码，账户被锁定30分钟', ErrorCodeEnum::STATUS_ERROR_PASSWORD_WRONG);
                    }
                }
                //return('{"success":false,"msg":"密码错误,这是你第'.$count.'次,一共5次机会"}');
                // $mess['code'] = '3';
                // $mess['mess'] = '密码错误,这是你第'.$count.'次,一共5次机会';
                // return $mess;
                throw new Exception('密码错误,这是你第'.$count.'次,一共5次机会', ErrorCodeEnum::STATUS_ERROR_PASSWORD_WRONG);
            }else{
                // cookie('logins', $user . '_1');
                $logins=1;
                $array=array(
                    'number'    =>$logins,
                    'user_id'   => $asda['user_id'],
                    'locktime'  =>time(),
                    'ip'        =>$_SERVER['REMOTE_ADDR'],
                );
                $LookUserd= $this->mLookUser->insert($array);
            }
            if (empty($LookUsersa->number)) {
                // $mess['code'] = '3';
                // $mess['mess'] = "密码错误,这是你第1次,一共5次机会";
                // return $mess;
                throw new Exception('密码错误,这是你第1次,一共5次机会', ErrorCodeEnum::STATUS_ERROR_PASSWORD_WRONG);
            }

        }
    }

    /**
     * 体验标支付动作
     */
    public  function AjaxSubmitExperient($paramObj){
        $user_id = session_get(UserEnum::USER_INFO_USER_ID);

        if(empty($user_id)){
            throw new Exception('用户未登录！', ErrorCodeEnum::STATUS_ERROR_NOT_LOGIN);
        }
        if(empty($paramObj->experience)){
            throw new Exception($this->error_msg[ProfessionErrorCodeEnum::STATUS_ERROR_PARAMS_MUST],
                ProfessionErrorCodeEnum::STATUS_ERROR_PARAMS_MUST);
        }
        if(!is_numeric($paramObj->experience)){
            throw new Exception('金额必须是数字！', ErrorCodeEnum::STATUS_ERROR_EXPERIENCE_MONEY);
        }
        if($paramObj->experience<10000){
            throw new Exception('金额至少10000元！', ErrorCodeEnum::STATUS_ERROR_EXPERIENCE_MONEY);
        }
        if($paramObj->experience%10000!==0){
            throw new Exception('请输入10000元的整数倍！', ErrorCodeEnum::STATUS_ERROR_EXPERIENCE_MONEY);
        }
        $ExperRecordOne=$this->mExperScale->ExperRecordOne($user_id);
        $ExperRecord=$this->mExperScale->ExperRecord($user_id);
        if(empty($ExperRecordOne)||$ExperRecord->scale<$paramObj->experience){
            throw new Exception('体验金不足', ErrorCodeEnum::STATUS_ERROR_EXPERIENCE_MONEY);
        }
        $t_id=$ExperRecord->t_id;
        $data=array(
            'project_name'  =>'体验标',
            'exper_money'   =>$paramObj->experience,//金额
            'exper_annua'   =>10,//年利率
            'exper_nums'    =>1,//期限
            'exper_time'    =>time(),
            'user_id'       =>$user_id,
        );
        $ExperRecord= $this->mExperRecord->insert($data);
        $updata=array(
            'statue'=>2,
        );
        $Scale=$this->mExperScale->update($updata,['t_id'=>$t_id]);
        if(!empty($ExperRecord)&&!empty($Scale)){
            return 1;
        }
    }

    /**
     * 插入充值
     * @param $paramObj
     * @return int
     */
    public function Rechargeinsert($paramObj)
    {
        #接受信息
        $aData = [
            'orderid'           =>$paramObj->id,
            'rechar_money'      =>$paramObj->amount,
            'oper_time'         =>$paramObj->time,
            'status'            =>1,
            'user_id'           =>$paramObj->uid,
            'type'              =>1
        ];
        return $this->mRechargeRecord->insert($aData);
        // return  $aData;
    }

    /**
     * 提现密码
     * @return mixed
     */
    public function AjaxWithdraw($paramObj)
    {
        //$asda=session_get(UserEnum::USER_INFO_SESSION_KEY);
        $user_id = session_get(UserEnum::USER_INFO_USER_ID);
        if(empty($user_id)){
            throw new Exception('用户未登录！', ErrorCodeEnum::STATUS_ERROR_NOT_LOGIN);
        }
        if(empty($paramObj->pay_pwd)){
            throw new Exception('密码不能为空', ProfessionErrorCodeEnum::ERROR_PASSWORD_NULL);
        }
        if(empty($paramObj->moneysum)||empty($paramObj->pay_pwd)){
            throw new Exception($this->error_msg[ProfessionErrorCodeEnum::STATUS_ERROR_PARAMS_MUST],
                ProfessionErrorCodeEnum::STATUS_ERROR_PARAMS_MUST);
        }
        //银行卡
        $bankmange=$this->mBankManage->GetBankManageOne($user_id);
        if(!empty($bankmange)){
            if( $bankmange->status!='2'){
            throw new Exception('银行卡信息不全', ProfessionErrorCodeEnum::ERROR_PASSWORD_NULL);
            }
        }else{
            throw new Exception('银行卡不能为空', ProfessionErrorCodeEnum::ERROR_PASSWORD_NULL);
        }
        $UserInfoPwd=$this->mUser->ApiGetUserInfoPwd($user_id);
        $pay_num=$UserInfoPwd->pay_num;//随机数
        $pwd    =md5(md5($paramObj->pay_pwd).$pay_num);
        $moneys     =$paramObj->moneysum;//支付金额
        $UserE      =$this->mUserExtend->UserExtendone($user_id);//获取总金额
        $amount     =$UserE->user_balance;//账户总金额
        $in_amo=$amount-$moneys;
        if($in_amo<0||$amount<$moneys){
            throw new Exception('余额不足', ErrorCodeEnum::STATUS_ERROR_NOT_MONEY);
        }
        $LookUsers  =$this->mLookWithdraw->lockwithdraw($user_id);//获取人是不是本冻结
        $lockwione  =$this->mLookWithdraw->lockwithdrawone($user_id);//获取人是不是本冻结
        if(!empty($lockwione)){
            $timelock = $lockwione->locktime;//获得当前时间戳 $v->datetime
            $timelock2 = $timelock+60*60*12;//到期时间
            // return $timelock2;
            if($timelock2 < time()){
                $LookUseraaaa=$this->mLookWithdraw->delete(['user_id'=>$user_id]);
            }
        }
        if(!empty($LookUsers)){//如果被冻结，看是否到解锁时间
            $LookUsersa  =$this->mLookWithdraw->lockwithdrawone($user_id);//获取人是不是本冻结
            if(time()<$LookUsersa->locktime){
                throw new Exception('对不起，您的账户已被锁定,请于'.date('Y-m-d H:i:s',$LookUsersa->locktime).'后尝试登录！', ErrorCodeEnum::STATUS_ERROR_PASSWORD_WRONG);
            }else{
                $LookUseraaaa=$this->mLookWithdraw->delete(['user_id'=>$user_id]);
            }
        }
        if ($pwd==$UserInfoPwd->pay_pwd){
            $aData= array(
                'user_balance'  =>$in_amo,//投资完的资金
            );
            $rdata=array(
                'bank_num'      =>$bankmange->bank_num,
                'name'          =>$bankmange->bound_name,
                'moneynum'      =>$paramObj->moneysum,
                'user_id'       =>$user_id,
                'time'          =>time()
            );
            // print_r($rdata);
            $dataextend= $this->mUserExtend->update($aData,['user_id' =>$user_id]);
            $dataRecord= $this->mDeposit->insert($rdata);
            if (!empty($dataextend)&&!empty($dataRecord)) {
                return 1;
            }
        }else{
            $LookUsersa  =$this->mLookWithdraw->lockwithdrawone($user_id);//获取本人有没有输入
            // print_r($LookUsersa->number);
            if(!empty($LookUsersa->number)){
                // $tmpArr = explode('_',$LookUsersa->number);
                $count = $LookUsersa->number;
                if($count<= 4){
                    $count++;
                    $logins=$count;
                    $array=array(
                        'number'    =>$logins,
                        'user_id'   =>$user_id,
                        'locktime'  =>time(),
                        'ip'        =>$_SERVER['REMOTE_ADDR'],
                    );
                    if ($count<1) {
                        $LookUserd= $this->mLookWithdraw->insert($array);
                    }
                    if ($count>0&&$count<=4) {
                        $LookUserd= $this->mLookWithdraw->update($array,['id' => $LookUsersa->id]);
                    }

                }
                if($count == 5){
                    $data4['number'] = $count;
                    $data4['user_id'] = $user_id;
                    $data4['locktime'] = time()+60*30;
                    $data4['ip'] = $_SERVER['REMOTE_ADDR'];
                    $LookUserd= $this->mLookWithdraw->update($data4,['id' => $LookUsersa->id]);
                    if (!empty($LookUserd)) {
                        throw new Exception('您已经连续5次输入错误密码，账户被锁定30分钟', ErrorCodeEnum::STATUS_ERROR_PASSWORD_WRONG);
                    }
                }
                throw new Exception('密码错误,这是你第'.$count.'次,一共5次机会', ErrorCodeEnum::STATUS_ERROR_PASSWORD_WRONG);
            }else{
                // cookie('logins', $user . '_1');
                $logins=1;
                $array=array(
                    'number'    =>$logins,
                    'user_id'   => $user_id,
                    'locktime'  =>time(),
                    'ip'        =>$_SERVER['REMOTE_ADDR'],
                );
                $LookUserd= $this->mLookWithdraw->insert($array);
            }
            if (empty($LookUsersa->number)) {
                throw new Exception('密码错误,这是你第1次,一共5次机会', ErrorCodeEnum::STATUS_ERROR_PASSWORD_WRONG);
            }

        }


    }

    /**
     * 插入银行卡信息
     * @param $paramObj
     * @return int
     */
    public function UserMoneyajax($paramObj)
    {
        #接受信息
        $bankmange=$this->mBankManage->GetBankManageyeno($paramObj->uid);
        if(empty($bankmange)){
            $aData = [
                'bank_num' => $paramObj->specBankCardNo,
                'user_id' => $paramObj->uid,
                'status' => 1,
                'created' => time(),
            ];
            return $this->mBankManage->insert($aData);
        }

    }

    /**
     * 投资状态修改
     * @return mixed
     *2016.7.6
     */
    public  function  UserAccountstatue(){
        $user_id    = session_get(UserEnum::USER_INFO_USER_ID);
        if(empty($user_id)){
            throw new Exception('用户未登录！', ErrorCodeEnum::STATUS_ERROR_NOT_LOGIN);
        }
        $InvestTicket = $this->mUser->UserInvestTicket($user_id);

        //return $InvestTicket;
        foreach ($InvestTicket as $key => $v) {
            $data = date("Y-m-d H:i:s", $v->invest_time);
            $time3 = strtotime(date("Y-m-d H:i:s", time()));//获得当前时间戳 $v->datetime
            $time2 = strtotime(date("Y-m-d H:i:s", strtotime("$data+ $v->limit day")));//到期时间

            if($v->status!=3){
            if ($time2 >= $time3) {
                $aData = array(
                    'status' => 2,
                );
                $this->mInvestRecord->update($aData, ['invest_time' => $v->invest_time,'user_id'=> $user_id]);
            }else{
                $aData = array(
                    'status' => 1,
                );
                $this->mInvestRecord->update($aData, ['invest_time' => $v->invest_time,'user_id'=> $user_id]);
            }
        }
        }
        return $InvestTicket;
    }


    /**
     * 账户信息收益正在进行
     * @return mixed
     */
    public function UserAccountpende(){
        $year=date("Y");//判断年份
        $user_id    = session_get(UserEnum::USER_INFO_USER_ID);
        if(empty($user_id)){
            throw new Exception('用户未登录！', ErrorCodeEnum::STATUS_ERROR_NOT_LOGIN);
        }
        $ticket     =$this->mUser->InvestTicketpende($user_id);
        //修改投资状态是否到期
        $expersum   =ApiService::instance()->experiencemoneyno();//体验金是否为空
        if(!empty($ticket)){
            $str='';
            foreach ($ticket as $k => $v) {
                $str += $v->invest_money*$v->limit*($v->yield_rate/100);
            }
            if(($year%4==0)&&($year%100!=0)||($year%400==0)){
//                $gains=round(($str/366)+$expersum,2);
                $str=$str/366;
                $gains=bcadd($str, $expersum,2);
                return $gains;
            }else{
//                $gains=round(($str/365)+$expersum,2);
                $str=$str/365;
                $gains=bcadd($str, $expersum,2);
                return  $gains;
            }


        }else{
            $gains=$expersum+0;
            return  $gains;
        }
    }

    /**
     *体验金收益未完成金额
     */
    public function experiencemoneyno()
    {
        $user_id = session_get(UserEnum::USER_INFO_USER_ID);
        if(empty($user_id)){
            throw new Exception('用户未登录！', ErrorCodeEnum::STATUS_ERROR_NOT_LOGIN);
        }
        $experiencemoney = $this->mUser->experiencemoney($user_id);

        //return $experiencemoney;
        if(!empty($experiencemoney)){
            $money  = $experiencemoney[0]->exper_money;//金额
            $nums   = $experiencemoney[0]->exper_nums;//期限
            $time   = $experiencemoney[0]->exper_time;//投资时间
            $annua  = $experiencemoney[0]->exper_annua / 100;//年利率
            if(empty($money)||empty($nums)||empty($time)||empty($annua)){
                throw new Exception($this->error_msg[ProfessionErrorCodeEnum::STATUS_ERROR_PARAMS_MUST],
                    ProfessionErrorCodeEnum::STATUS_ERROR_PARAMS_MUST);
            }
            $shouyi = $money * $nums * $annua;
            $time3  =strtotime(date("Y-m-d H:i:s",time()));//获得当前时间戳
            $time2  =strtotime(date("Y-m-d H:i:s",$time+60*60*24));//到期时间
            if ($time2 >= $time3){
                $year=date("Y");//判断年份
                if(($year%4==0)&&($year%100!=0)||($year%400==0)){
                    $gains=round($shouyi/366,2);
                    return $gains;
                }else{
                    $gains=round($shouyi/365,2);
                    return  $gains;
                }
            }
        }else{

            return 0;
        }

    }
    /**
     * 账户信息收益完成
     * @return mixed
     */
    public function UserAccountsussful(){
        $year=date("Y");//判断年份
        $user_id    = session_get(UserEnum::USER_INFO_USER_ID);
        if(empty($user_id)){
            throw new Exception('用户未登录！', ErrorCodeEnum::STATUS_ERROR_NOT_LOGIN);
        }
        $ticket     =$this->mUser->InvestTicketgains($user_id);
        //修改投资状态是否到期
        $expersum   =ApiService::instance()->experiencemoney();//体验金是否为空
        if(!empty($ticket)){
            $str='';
            foreach ($ticket as $k => $v) {
                $str += $v->invest_money*$v->limit*($v->yield_rate/100);
            }
            if(($year%4==0)&&($year%100!=0)||($year%400==0)){
                $str=$str/366;
                $gains=bcadd($str, $expersum,2);
                return $gains;
            }
            else{
                $str=$str/365;
                $gains=bcadd($str, $expersum,2);
                return  $gains;
            }

        }else{
            $gains=$expersum+0;
            return  $gains;
        }
    }

    /**
     *账户可用余额
     */
    public  function UserExtendone(){
        $user_id    = session_get(UserEnum::USER_INFO_USER_ID);
        if(empty($user_id)){
            throw new Exception('用户未登录！', ErrorCodeEnum::STATUS_ERROR_NOT_LOGIN);
        }
        $UserExtend=$this->mUserExtend->UserExtendone($user_id);
        return $UserExtend;
    }

    /**
     * 插入充值记录
     * @param $paramObj
     * @return int
     */
    public function Checkinsert($paramObj){
        #接受信息
        $aData = [
            'recharge_money'      =>$paramObj->amount,
            'year'              =>date('Y', $paramObj->time),
            'month'             =>date('n', $paramObj->time),
            'day'               =>date('j', $paramObj->time),
            'user_id'           =>$paramObj->uid,
        ];
        $LineChart  =$this->mLineChart->linechartpay($paramObj->uid,date('Y', $paramObj->time),date('n', $paramObj->time),date('j',$paramObj->time));
        if(!empty($LineChart)){
            $LineChartone  =$this->mLineChart->linechartone($paramObj->uid,date('Y', $paramObj->time),date('n', $paramObj->time),date('j',$paramObj->time));
            $countmoneys= $paramObj->amount+$LineChartone->recharge_money;
            $cart=array(
                'recharge_money'    =>$countmoneys,
                'time'               =>  $paramObj->time,
                'user_id'            =>  $paramObj->uid
            );
            $this->mLineChart->update($cart,['id' =>$LineChartone->id]);

        }else{
            $this->mLineChart->insert($aData);//柱状图
        }
        return 1;

    }

    /**
     * 插入充值金额
     * @param $paramObj
     * @return int
     */
    public  function Extendmoney($paramObj){
        $UserE      =$this->mUserExtend->UserExtendone($paramObj->uid);//获取总金额
        $amounts     =$UserE->user_balance;//账户总金额
        if(!empty($amounts)){
            $amount     =bcadd($amounts, $paramObj->amount,2);//账户总金额
        }else{
            $amount     =$paramObj->amount;
        }
        #接受信息
        $aData = [
            'user_balance'      =>$amount,
            'user_id'           =>$paramObj->uid
        ];
        $Extend=$this->mUserExtend->update($aData,['user_id' =>$paramObj->uid]);
        if(!empty($Extend)){
            $this->XG($paramObj->uid,'充值成功','您已成功充值'.$paramObj->amount.'元。');
            return 1;
        }
        return 0;


    }


    /**
     *个人信息展示
     */
    public  function UserInfone(){
        $user_id    = session_get(UserEnum::USER_INFO_USER_ID);
        if(empty($user_id)){
            throw new Exception('用户未登录！', ErrorCodeEnum::STATUS_ERROR_NOT_LOGIN);
        }
        $user_info = $this->mUser->ApiGetUserInfo($user_id);

        return $user_info;

    }

    public  function UseBankManager(){
        $user_id    = session_get(UserEnum::USER_INFO_USER_ID);
        if(empty($user_id)){
            throw new Exception('用户未登录！', ErrorCodeEnum::STATUS_ERROR_NOT_LOGIN);
        }
        $bank_info = $this->mBankManage->BankInfo($user_id);


        return $bank_info;

    }

    /**
     * 投资到期收益
     * @return mixed
     *2016.7.11
     */
    public  function  UserAccountshouyi(){
        $user_id    = session_get(UserEnum::USER_INFO_USER_ID);

        if(empty($user_id)){
            throw new Exception('用户未登录！', ErrorCodeEnum::STATUS_ERROR_NOT_LOGIN);
        }
        $year=date("Y");//判断年份
        $InvestTicket = $this->mUser->InvestTicketgains($user_id);//获取投资记录到期的
        //return $InvestTicket;
        $UserE      =$this->mUserExtend->UserExtendone($user_id);//获取总金额
        $amount     =$UserE->user_balance;//账户总金额

        if(!empty($InvestTicket)){
            $str='';
            foreach ($InvestTicket as $key => $v) {
                $data = date("Y-m-d H:i:s", $v->invest_time);
                $time3 = strtotime(date("Y-m-d H:i:s", time()));//获得当前时间戳 $v->datetime
                $time2 = strtotime(date("Y-m-d H:i:s", strtotime("$data+ $v->limit day")));//到期时间
                // $time2  =strtotime(date("Y-m-d H:i:s",$v->invest_time+60*60*3));//到期时间测试

                if ($time2 <= $time3) {//到期收益
                    if($v->status!='3'){
                    $str += $v->invest_money * $v->limit * ($v->yield_rate / 100);

                    //修改状态
                    $aDatae = array(
                        'status' => 3,
                    );
                    $asd = $this->mInvestRecord->update($aDatae, ['invest_id' => $v->invest_id]);

                    }
                } else {
                    $str = 0;
                }

            }

        }else{
            $str=0;
        }

        if(($year%4==0)&&($year%100!=0)||($year%400==0)){//
            $gains=round(($str/366),2);

            if(!empty($amount)){
                $amounts     =$UserE->user_balance+$gains;//账户总金额

            }else{
                $amounts     =$gains;
            }
            #接受信息
            $aData = [
                'user_balance'      =>$amounts,
                'user_id'           =>$user_id
            ];
            $this->mUserExtend->update($aData,['user_id' =>$user_id]);

        }else{
            $gains=round(($str/365),2);
            if(!empty($amount)){
                $amounts     =$UserE->user_balance+$gains;//账户总金额
            }else{
                $amounts     =$gains;
            }
            #接受信息
            $aData = [
                'user_balance'      =>$amounts,
                'user_id'           =>$user_id
            ];
            $this->mUserExtend->update($aData,['user_id' =>$user_id]);
        }


    }
    /**
     *体验金收益完成入库
     *体验金如果只有一个，多个则改成数组
     */
    public function experienceshouyi()
    {
        $user_id = session_get(UserEnum::USER_INFO_USER_ID);
        if(empty($user_id)){
            throw new Exception('用户未登录！', ErrorCodeEnum::STATUS_ERROR_NOT_LOGIN);
        }
        $experiencemoney = $this->mUser->experiencemoney($user_id);
        //return $experiencemoney;
        $UserE      =$this->mUserExtend->UserExtendone($user_id);//获取总金额
        $amount     =$UserE->user_balance;//账户总金额
        if(!empty($experiencemoney)&&$experiencemoney[0]->status!=3){
            $money  = $experiencemoney[0]->exper_money;//金额
            $nums   = $experiencemoney[0]->exper_nums;//期限
            $time   = $experiencemoney[0]->exper_time;//投资时间
            $annua  = $experiencemoney[0]->exper_annua / 100;//年利率
            if(empty($money)||empty($nums)||empty($time)||empty($annua)){
                throw new Exception($this->error_msg[ProfessionErrorCodeEnum::STATUS_ERROR_PARAMS_MUST],
                    ProfessionErrorCodeEnum::STATUS_ERROR_PARAMS_MUST);
            }
            $shouyi = $money * $nums * $annua;
            $time3  =strtotime(date("Y-m-d H:i:s",time()));//获得当前时间戳
            $time2  =strtotime(date("Y-m-d H:i:s",$time+60*60*24));//到期时间
            if ($time2 <= $time3){

                $year=date("Y");//判断年份
                if(($year%4==0)&&($year%100!=0)||($year%400==0)){
                    $gains=round($shouyi/366,2);
                }else{
                    $gains=round($shouyi/365,2);
                }
                if(!empty($amount)){
                    $amounts     =$UserE->user_balance+$gains;//账户总金额
                }else{
                    $amounts     =$gains;
                }
                #到期金额入库
                $aData = [
                    'user_balance'      =>$amounts,
                    'user_id'           =>$user_id
                ];
                $success=$this->mUserExtend->update($aData,['user_id' =>$user_id]);
                if(!empty($success)){
                    $aDatae = array(
                        'status' => 3,
                    );
                    $this->mExperRecord->update($aDatae,['ex_id' =>$experiencemoney[0]->ex_id]);
                }

            }
        }

    }




    /**
     * 获取所有关联信息
     */
    public  function Relevance($arr = array(),$name)
    {
        $arrRes = array();
        foreach ($arr as $v) {
            if (!in_array($v->$name, $arrRes)) {
                $arrRes[] = $v->$name;
            }
        }
        return $arrRes;
    }

    /**
     * 将array的每个val转化成key
     */
    public function VelToKey($arr = array(),$key_name){
        $arrRes = array();
        foreach($arr as $k => &$v){
            $arrRes[$v->$key_name] = $arr[$k];
        }
        return $arrRes;
    }


    /**
     * 获取App信息
     * @author  lzhp
     * @date    2016-07-08
     * @throws Exception
     */
    public function GetIndexApp(){
        $app_info = $this->mVersion->GetVersion();
        $app_info->token = QiniuUpload::instance()->generateToken();
        $bankeleobj = new bankele();
        $bank_token=$bankeleobj->getToken();
        return $data=[
            'app_info'  =>$app_info,
            'bank_token'  =>$bank_token,
        ];
    }



    /**
     * 用户注册
     * @param $paramObj
     * @author lzhp
     * @date 2016-6-25
     * @return mixed
     * @throws Exception
     */
    public function DeposeRegister($paramObj)
    {
        #参数验证
        $check = $this->checkProperties($paramObj, ['mobile', 'password']);
        if (!$check) {
            throw new Exception($this->error_msg[ProfessionErrorCodeEnum::STATUS_ERROR_PARAMS_MUST],
                ProfessionErrorCodeEnum::STATUS_ERROR_PARAMS_MUST);
        }

        #密码验证
        if(!preg_match('/^\w{6,16}$/',$paramObj->password)){
            throw new Exception("密码必须为6-16位的数字或字符", ProfessionErrorCodeEnum::ERROR_PASSWORD_FAILURE);
        }

        #手机号验证
        if (!preg_match('/^1[34578]\d{9}$/', $paramObj->mobile)) {
            throw new Exception("手机号码错误", ProfessionErrorCodeEnum::ERROR_USER_MOBILE_FAILURE);
        }

        #手机号是否已注册
        $mobile = $this->mUser->JsCheckMobile($paramObj->mobile);
        if ($mobile) {
            throw new Exception("手机号已注册", ProfessionErrorCodeEnum::ERROR_ACCOUNT_EXIST);
        }

        if(!empty($paramObj->invite_mobile)){
            $invite_mobile = $this->mUser->JsCheckInvite($paramObj->invite_mobile);
            #邀请人手机号验证
            if (!$invite_mobile) {
                throw new Exception("邀请人手机号不存在", ProfessionErrorCodeEnum::ERROR_USER_MOBILE_FAILURE);
            }
        }


    #注册用户
        $aData = [
            'password'           =>     md5($paramObj->password),
            'mobile'             =>     $paramObj->mobile,
            'avatar'             =>     'api.yangpiaotong.com/resource/img/user_img.png',
            'user_name'          =>     'ypt_'.$this->random_str(9),
            'created'            =>     time()
        ];

        $user_id = $this->mUser->insert($aData);

        if($user_id){
            if(!empty($paramObj->invite_mobile)){
                $invite = $this->mUser->JsCheckInvite($paramObj->invite_mobile);
                if($invite){
                    $aData2 = [
                        'bu_id'      => $user_id,
                        'u_id'      =>  $invite->user_id,
                        'reward'     =>  '10',
                        'datetime'   =>  '30',
                        'time'       =>  time(),
                        'access'     =>  '注册获取',
                        'statue'     =>  1,
                        'apply'      => '通用',
                        'rewamoney'      => '1000'
                    ];
                    $this->mInvitie->insert($aData2);
                    $aData3 = [
                        'u_id'     =>  $user_id,
                        'reward'    =>  '10',
                        'datetime'   =>  '30',
                        'time'      =>  time(),
                        'access'    =>  '注册获取',
                        'statue'    =>  0,
                        'apply'      => '通用',
                        'rewamoney'      => '1000'
                    ];
                    $this->mInvitie->insert($aData3);
                }
            }else{
                if(!empty($paramObj->invite_id)){
                    $aData2 = [
                        'bu_id'      =>  $user_id,
                        'u_id'       =>   $paramObj->invite_id,
                        'reward'     =>  '10',
                        'datetime'   =>  '30',
                        'time'       =>  time(),
                        'access'     =>  '注册获取',
                        'statue'     =>  0,
                        'apply'      => '通用',
                        'rewamoney'      => '1000'
                    ];
                    $this->mInvitie->insert($aData2);
                    $aData3 = [
                        'u_id'     =>  $user_id,
                        'reward'    =>  '10',
                        'datetime'   =>  '30',
                        'time'      =>  time(),
                        'access'    =>  '注册获取',
                        'statue'    =>  0,
                        'apply'      => '通用',
                        'rewamoney'      => '1000'
                    ];
                    $this->mInvitie->insert($aData3);
                }else{
                    $aData2 = [
                        'u_id'     =>  $user_id,
                        'reward'    =>  '10',
                        'datetime'   =>  '30',
                        'time'      =>  time(),
                        'access'    =>  '注册获取',
                        'statue'    =>  0,
                        'apply'      => '通用',
                        'rewamoney'      => '1000'
                    ];
                    $this->mInvitie->insert($aData2);
                }
            }
            $aData3=[
                'scale'      =>  '10000',
                'time'       =>  time(),
                'datetime'   =>  '30',
                'access'     =>  '注册获取',
                'user_id'    =>  $user_id,
                'statue'     =>   0,
            ];

            $this->mExperScale->insert($aData3);
            $this->mUserExtend->insert(['user_id'=>$user_id]);
        }else{
            throw new Exception("注册失败", ProfessionErrorCodeEnum::ERROR_DB_UPDATE);
        }

        $invite_mobile = $this->mUser->JsCheckInvite($paramObj->invite_mobile);
        if($invite_mobile){
            $mobile = substr_replace($paramObj->mobile,'****',3,4);
            $this->xg($invite_mobile->user_id,'奖励通知',"您已成功邀请好友$mobile,您的奖励已经进入账户，请在平台奖励进行查看。");
        }

        return  new stdClass();

    }

    /**
     * 注册验证手机号
     * @param $paramObj
     * @author lzhp
     * @date 2016-6-25
     * @return stdClass
     * @throws Exception
     */
    public function RegisterMobile($paramObj)
    {
        #参数验证
        $check = $this->checkProperties($paramObj, ['mobile']);
        if (!$check) {
            throw new Exception($this->error_msg[ProfessionErrorCodeEnum::STATUS_ERROR_PARAMS_MUST],
                ProfessionErrorCodeEnum::STATUS_ERROR_PARAMS_MUST);
        }
        #手机号验证
        if (!preg_match('/^1[34578]\d{9}$/', $paramObj->mobile)) {
            throw new Exception("手机号码错误", ProfessionErrorCodeEnum::ERROR_USER_MOBILE_FAILURE);
        }

        #手机号是否已注册
        $mobile = $this->mUser->JsCheckMobile($paramObj->mobile);
        if ($mobile) {
            throw new Exception("手机号已注册", ProfessionErrorCodeEnum::ERROR_ACCOUNT_EXIST);
        }

        return new stdClass();
    }

    /**
     * 用户登录
     * @param $paramObj
     * @author lzhp
     * @date   2016-6-25
     * @return mixed
     * @throws Exception
     */
    public function DeposeLogin($paramObj)
    {

        #参数验证
        $check = $this->checkProperties($paramObj, ['mobile', 'password']);
        if (!$check) {
            throw new Exception("参数不足", ProfessionErrorCodeEnum::STATUS_ERROR_PARAMS_MUST);
        }
        #用户登录
        $user_info = $this->mUser->login($paramObj->mobile, md5($paramObj->password));
        $user_info2 =  $this->mUser->login2($paramObj->mobile, md5($paramObj->password));

        if (!$user_info) {
            throw new Exception("用户名或密码错误", ProfessionErrorCodeEnum::STATUS_ERROR_PASSWORD_WRONG);
        }

        $arr1 = array();
        foreach($user_info as $k=>$v){
            if($v==''){
                $arr1[$k] = '';
            }else{
                $arr1[$k] = $v;
            }
        }
        $arr2 = array();
        if($user_info2){
            foreach($user_info2 as $k=>$v){
                if($v==''){
                    $arr2[$k] = '';
                }else{
                    $arr2[$k] = $v;
                }
            }
        }else{
            $arr2 = null;
        }

        session_put(UserEnum::USER_INFO_USER_ID, $user_info->user_id);
        session_put(UserEnum::USER_INFO_SESSION_KEY, $arr1);

        return $aData=[
            'user_info' => $arr1,
            'bank_info' => $arr2
        ];

    }

    /**
     * 自动登录
     * @param $paramObj
     * @return array
     * @throws Exception
     */
    public function AutoLogin($paramObj)
    {
        #参数验证
        $check = $this->checkProperties($paramObj, ['user_id']);
        if (!$check) {
            throw new Exception("参数不足", ProfessionErrorCodeEnum::STATUS_ERROR_PARAMS_MUST);
        }

        $user_info = $this->mUser->ApiGetUserInfo($paramObj->user_id);
        $bank_info = $this->mBankManage->BankInfo($paramObj->user_id);

        $arr1 =array();
        if($user_info){
            foreach($user_info as $k=>$v){
                if($v==''){
                    $arr1[$k] = '';
                }else{
                    $arr1[$k] = $v;
                }
            }
        }else{
            $arr1 = new stdClass();
        }

        $arr2 =array();
        if($bank_info){
            foreach($bank_info as $k=>$v){
                if($v==''){
                    $arr2[$k] = '';
                }else{
                    $arr2[$k] = $v;
                }
            }
        }else{
            $arr2 = null;
        }

        session_put(UserEnum::USER_INFO_USER_ID, $user_info->user_id);
        session_put(UserEnum::USER_INFO_SESSION_KEY, $arr1);

        return $aData=[
            'user_info' => $arr1,
            'bank_info' => $arr2,
        ];

    }


    /**
     * 用户注销
     * @return bool
     * @throws Exception
     * @author lzhp
     * @data   2016-6-25
     */
    public function LoginOut()
    {
        #验证登录
        if (!session_has(UserEnum::USER_INFO_SESSION_KEY))
            throw new Exception('用户未登录！', ErrorCodeEnum::STATUS_ERROR_NOT_LOGIN);


        #清空SESSION
        Session::flush();

        return new stdClass();
    }


    /**
     * 忘记密码手机验证
     * @param $paramObj
     * @return stdClass
     * @throws Exception
     */
    public function ForgetPasswordMobile($paramObj)
    {

        #参数验证
        $check = $this->checkProperties($paramObj, ['mobile']);
        if (!$check) {
            throw new Exception("参数不足", ProfessionErrorCodeEnum::STATUS_ERROR_PARAMS_MUST);
        }
        #手机号验证
        if (!preg_match('/^1[34578]\d{9}$/', $paramObj->mobile)) {
            throw new Exception("手机号码错误", ProfessionErrorCodeEnum::ERROR_USER_MOBILE_FAILURE);
        }

        #手机号是否已注册
        $mobile = $this->mUser->JsCheckMobile($paramObj->mobile);
        if (!$mobile) {
            throw new Exception("用户手机号不存在", ProfessionErrorCodeEnum::ERROR_ACCOUNT_NOT_EXIST);
        }

        return new stdClass();
    }


    /**
     * 忘记密码
     * @param $paramObj
     * @return bool
     * @throws Exception
     */
    public function ForgetPassword($paramObj)
    {
        #参数验证
        $check = $this->checkProperties($paramObj, ['mobile','password']);
        if (!$check) {
            throw new Exception("参数不足", ProfessionErrorCodeEnum::STATUS_ERROR_PARAMS_MUST);
        }
        #手机号验证
        if (!preg_match('/^1[34578]\d{9}$/', $paramObj->mobile)) {
            throw new Exception("手机号码错误", ProfessionErrorCodeEnum::ERROR_USER_MOBILE_FAILURE);
        }

        #手机号是否已注册
        $mobile = $this->mUser->JsCheckMobile($paramObj->mobile);
        if (!$mobile) {
            throw new Exception("用户手机号不存在", ProfessionErrorCodeEnum::ERROR_ACCOUNT_NOT_EXIST);
        }

        #密码验证
        if(!preg_match('/^\w{6,16}$/',$paramObj->password)){
            throw new Exception("密码必须为6-16位的数字或字符", ProfessionErrorCodeEnum::ERROR_PASSWORD_FAILURE);
        }


        $aData=[
            'password'      =>  md5($paramObj->password),
        ];

        $this->mUser->update($aData,['mobile'=>$paramObj->mobile]);

         return new stdClass();
    }

    /**
     * 实名认证
     * @param $paramObj
     * @return stdClass
     * @throws Exception
     * @author lzhp
     * @data 2016-6-28
     */
    public function AuthName($paramObj)
    {
        #验证登录
        if (!session_get(UserEnum::USER_INFO_SESSION_KEY))
            throw new Exception('用户未登录！', ErrorCodeEnum::STATUS_ERROR_NOT_LOGIN);


        $user_id = session_get(UserEnum::USER_INFO_USER_ID);

        #参数验证
        $check = $this->checkProperties($paramObj, ['real_name','id_card']);
        if (!$check) {
            throw new Exception("参数不足", ProfessionErrorCodeEnum::STATUS_ERROR_PARAMS_MUST);
        }

        #姓名验证
        if(!preg_match('/^[\x80-\xff]{4,18}$/',$paramObj->real_name)){
            throw new Exception("姓名格式错误", ProfessionErrorCodeEnum::ERROR_NAME_FORMAT);
        }

         #身份证验证
        if (!preg_match('/^(\d{15}$|^\d{18}$|^\d{17}(\d|X|x))$/', $paramObj->id_card)) {
            throw new Exception("身份证格式错误",ProfessionErrorCodeEnum::ERROR_ID_CARD_FORMAT);
        }

        #身份证是否已经被绑定
        $id_card = $this->mUser->CheckCard($paramObj->id_card);
        if($id_card){
            throw new Exception("身份证已经被绑定",ProfessionErrorCodeEnum::ERROR_ID_CARD_FORMAT);
        }

        #该用户是否实名认证过
        $is = $this->mUser->CheckIsCard($user_id);
        if($is->id_card){
            throw new Exception("该用户已经实名认证过",ProfessionErrorCodeEnum::ERROR_ID_CARD_FORMAT);
        }

        return new stdClass();
    }

    /**
     * 设置密码
     * @param $paramObj
     * @return mixed
     * @throws Exception
     * @author lzhp
     * @data 2016-6-28
     */
    public function PayPassword($paramObj)
    {
        #验证登录
        if (!session_get(UserEnum::USER_INFO_SESSION_KEY))
            throw new Exception('用户未登录！', ErrorCodeEnum::STATUS_ERROR_NOT_LOGIN);

        $user_id = session_get(UserEnum::USER_INFO_USER_ID);

        #参数验证
        $check = $this->checkProperties($paramObj, ['real_name','id_card','pay_pwd']);
        if (!$check) {
            throw new Exception("参数不足", ProfessionErrorCodeEnum::STATUS_ERROR_PARAMS_MUST);
        }

        #姓名验证
        if(!preg_match('/^[\x80-\xff]{4,18}$/',$paramObj->real_name)){
            throw new Exception("姓名格式错误", ProfessionErrorCodeEnum::ERROR_NAME_FORMAT);
        }

        #身份证验证
        if (!preg_match('/^(\d{15}$|^\d{18}$|^\d{17}(\d|X|x))$/', $paramObj->id_card)) {
            throw new Exception("身份证格式错误",ProfessionErrorCodeEnum::ERROR_ID_CARD_FORMAT);
        }

        #身份证是否已经被绑定
        $id_card = $this->mUser->CheckCard($paramObj->id_card);
        if($id_card){
            throw new Exception("身份证已经被绑定",ProfessionErrorCodeEnum::ERROR_ID_CARD_FORMAT);
        }

        #该用户是否实名认证过
        $is = $this->mUser->CheckIsCard($user_id);
        if($is->id_card){
            throw new Exception("该用户已经实名认证过",ProfessionErrorCodeEnum::ERROR_ID_CARD_FORMAT);
        }

        #支付密码
//        if(!preg_match(' /^\d{6}$/',$paramObj->pay_pwd)){
//            throw new Exception("支付密码为六位数字", ProfessionErrorCodeEnum::ERROR_PASSWORD_FAILURE);
//        }

        $pay_num = rand(1000, 9999);
        $aData=[
            'real_name'      =>  $paramObj->real_name,
            'id_card'        =>  $paramObj->id_card,
            'pay_pwd'        =>  md5(md5($paramObj->pay_pwd).$pay_num),
            'pay_num'        => $pay_num
        ];

        $this->mUser->update($aData,['user_id'=>$user_id]);
        $user_info = $this->mUser->ApiGetUserInfo($user_id);

        $arr = array();
        foreach($user_info as $k=>$v){
            if($v==''){
                $arr[$k] = '';
            }else{
                $arr[$k] = $v;
            }
        }
        return $arr;
    }

    /**
     * 修改支付密码手机验证
     * @param $paramObj
     * @return stdClass
     * @throws Exception
     * @author lzhp
     * @data 2016-6-29
     */
    public function UpPayPasswordMobile($paramObj)
    {
        #验证登录
        if (!session_get(UserEnum::USER_INFO_SESSION_KEY))
            throw new Exception('用户未登录！', ErrorCodeEnum::STATUS_ERROR_NOT_LOGIN);
        $user_id = session_get(UserEnum::USER_INFO_USER_ID);

        #参数验证
        $check = $this->checkProperties($paramObj, ['mobile']);
        if (!$check) {
            throw new Exception("参数不足", ProfessionErrorCodeEnum::STATUS_ERROR_PARAMS_MUST);
        }

        #验证手机号
        $user_info = $this->mUser->ApiGetUserInfo($user_id);
        if($user_info->mobile != $paramObj->mobile){
            throw new Exception("手机号码错误", ProfessionErrorCodeEnum::ERROR_USER_MOBILE_FAILURE);
        }

        return new stdClass();
    }

    /**
     * 修改支付密码
     * @param $paramObj
     * @return stdClass
     * @throws Exception
     * @author lzhp
     * @data 2016-6-29
     */
    public function UpPayPassword($paramObj)
    {
        #验证登录
        if (!session_get(UserEnum::USER_INFO_SESSION_KEY))
            throw new Exception('用户未登录！', ErrorCodeEnum::STATUS_ERROR_NOT_LOGIN);
        $user_id = session_get(UserEnum::USER_INFO_USER_ID);

        #验证支付密码
        $pay_pwd = $this->mUser->ApiGetUserInfoPwd($user_id);
        if($pay_pwd->pay_pwd==''){
            throw new Exception("请先设置支付密码");
        }

        #参数验证
        $check = $this->checkProperties($paramObj, ['mobile','pay_pwd']);
        if (!$check) {
            throw new Exception("参数不足", ProfessionErrorCodeEnum::STATUS_ERROR_PARAMS_MUST);
        }

        #验证手机号
        $user_info = $this->mUser->ApiGetUserInfo($user_id);
        if($user_info->mobile != $paramObj->mobile){
            throw new Exception("手机号码错误", ProfessionErrorCodeEnum::ERROR_USER_MOBILE_FAILURE);
        }

        #支付密码
//        if(!preg_match(' /^\d{6}$/',$paramObj->pay_pwd)){
//            throw new Exception("支付密码为六位数字", ProfessionErrorCodeEnum::ERROR_PASSWORD_FAILURE);
//        }

        $pay_num = rand(1000, 9999);
        $aData=[
            'pay_pwd'        =>  md5(md5($paramObj->pay_pwd).$pay_num),
            'pay_num'        => $pay_num
        ];

        $this->mUser->update($aData,['user_id'=>$user_id]);

        return new stdClass();
    }

    /**
     * 修改登录密码
     * @param $paramObj
     * @return stdClass
     * @throws Exception
     * @author lzhp
     * @data 2016-6-29
     */
    public function UpLoginPassword($paramObj)
    {
        #验证登录
        if (!session_get(UserEnum::USER_INFO_SESSION_KEY))
            throw new Exception('用户未登录！', ErrorCodeEnum::STATUS_ERROR_NOT_LOGIN);
        $user_id = session_get(UserEnum::USER_INFO_USER_ID);

        #参数验证
        $check = $this->checkProperties($paramObj, ['old_pwd','new_pwd']);
        if (!$check) {
            throw new Exception("参数不足", ProfessionErrorCodeEnum::STATUS_ERROR_PARAMS_MUST);
        }

        #验证原密码
        $user_info = $this->mUser->ApiGetUserInfoPwd($user_id);
        if($user_info->password != md5($paramObj->old_pwd)){
            throw new Exception("密码错误", ProfessionErrorCodeEnum::ERROR_PASSWORD_WRONG);
        }

        #密码验证
        if(!preg_match('/^\w{6,16}$/',$paramObj->new_pwd)){
            throw new Exception("密码必须为6-16位的数字或字符", ProfessionErrorCodeEnum::ERROR_PASSWORD_FAILURE);
        }

        #验证新密码
        if(md5($paramObj->new_pwd) == $user_info->password){
            throw new Exception("新密码不能和旧密码重复", ProfessionErrorCodeEnum::ERROR_PASSWORD_FAILURE);
        }

        $aData=[
            'password'      =>  md5($paramObj->new_pwd),
        ];

        $this->mUser->update($aData,['user_id'=>$user_id]);

        return new stdClass();

    }

    /**
     * 投资记录
     * @param $paramObj
     * @return array|stdClass
     * @throws Exception
     * @author lzhp
     * @date 2016-06-29
     */
    public function InvestRecord($paramObj)
    {
        #验证登录
        if (!session_get(UserEnum::USER_INFO_SESSION_KEY))
            throw new Exception('用户未登录！', ErrorCodeEnum::STATUS_ERROR_NOT_LOGIN);
        $user_id = session_get(UserEnum::USER_INFO_USER_ID);


        if(!empty($paramObj->month)&&!empty($paramObj->year)){
            $first = mktime(0, 0, 0, date("$paramObj->month"), 1, date("$paramObj->year"));
            $end = mktime(23, 59, 59, date("$paramObj->month"), date("t"), date("$paramObj->year"));
        }else{
            $first = mktime(0, 0, 0, date("1"),1);
            $end = mktime(23, 59, 59, date("12"),31);
        }


        $invest = $this->mUser->SelInvestRecord($user_id,$first,$end,$paramObj->page);
//        $invest = json_encode($invest);
//        $invest = json_decode($invest,true);
//
//
//        $bid_record =  $this->mExperRecord->ExperBidRecordOne($user_id,$first,$end);
//        $bid_record = json_encode($bid_record);
//        $bid_record = json_decode($bid_record,true);
//
//        $arr = array_merge($invest,$bid_record);

       return $invest;


    }

    /**
     * 消息中心
     * @param $paramObj
     * @return array
     * @throws Exception
     * @author lzhp
     * @date 2016-06-30
     */
    public function MessageCenter($paramObj)
    {

        #验证登录
        if (!session_get(UserEnum::USER_INFO_SESSION_KEY))
            throw new Exception('用户未登录！', ErrorCodeEnum::STATUS_ERROR_NOT_LOGIN);
        $user_id = session_get(UserEnum::USER_INFO_USER_ID);

        $message = $this->mUser->MyMessage($user_id,$paramObj->page);
        $platform_notice = $this->mNews->PlatformNotice($paramObj->page);
        foreach($platform_notice as $k=>$v){
            $platform_notice[$k]->content =  strip_tags($v->content);
            $platform_notice[$k]->content =  preg_replace('/\r|\n|\t/','',$v->content);
            $platform_notice[$k]->content =  preg_replace('/&amp;emsp;/','',$v->content);
            $platform_notice[$k]->content =  preg_replace('/&nbsp|&emsp;/','',$v->content);
        }
        return $aData = [
          'message' => $message,
          'platform_notice' => $platform_notice,
        ];

    }

    /**
     * 银行卡绑定获取token
     * @param $paramObj
     * @return mixed
     * @throws Exception
     * @author lzhp
     * @date 2016-06-30
     */
    public function BankBound($paramObj)
    {
        #验证登录
        if (!session_get(UserEnum::USER_INFO_SESSION_KEY))
            throw new Exception('用户未登录！', ErrorCodeEnum::STATUS_ERROR_NOT_LOGIN);
        $user_id = session_get(UserEnum::USER_INFO_USER_ID);
        #参数验证
        $check = $this->checkProperties($paramObj, ['real_name','id_card','kaihuhang','bank_name','province','city','area','bank_num','bank_code','bank_token']);
        if (!$check) {
            throw new Exception("参数不足", ProfessionErrorCodeEnum::STATUS_ERROR_PARAMS_MUST);
        }

        $user_info = $this->mUser->ApiGetUserInfo($user_id);

        #是否绑定银行卡
        $bank_info = $this->mBankManage->SelUserBank($user_id);
        if($bank_info){
            throw new Exception("已经绑定银行卡",ProfessionErrorCodeEnum::ERROR_BANK_NUM);
        }

        #银行卡号验证
        if (!preg_match('/^(\d{16}|\d{19})$/', $paramObj->bank_num)) {
            throw new Exception("银行卡号格式错误",ProfessionErrorCodeEnum::ERROR_BANK_NUM);
        }

        if($user_info->real_name!=$paramObj->real_name){
            throw new Exception("姓名信息不符", ProfessionErrorCodeEnum::ERROR_NAME_FORMAT);
        }
        $auth = $this->mLog->BankAuth($paramObj,$user_info->mobile);

        if($auth['error']==0){
            return $auth['message'];
        }else{
            throw new Exception($auth['message'],1);
        }


//        #姓名验证
//        if(!preg_match('/^[\x80-\xff]{4,18}$/',$paramObj->real_name)){
//            throw new Exception("姓名格式错误", ProfessionErrorCodeEnum::ERROR_NAME_FORMAT);
//        }
//
//        #身份证验证
//        if (!preg_match('/^(\d{15}$|^\d{18}$|^\d{17}(\d|X|x))$/', $paramObj->id_card)) {
//            throw new Exception("身份证格式错误",ProfessionErrorCodeEnum::ERROR_ID_CARD_FORMAT);
//        }
//
//

    }

    /**
     * 银行卡修改获取token
     * @param $paramObj
     * @return stdClass
     * @throws Exception
     * @author lzhp
     * @date 2016-06-30
     */
    public function BankUp($paramObj)
    {
        #验证登录
        if (!session_get(UserEnum::USER_INFO_SESSION_KEY))
            throw new Exception('用户未登录！', ErrorCodeEnum::STATUS_ERROR_NOT_LOGIN);
        $user_id = session_get(UserEnum::USER_INFO_USER_ID);

        #参数验证
        $check = $this->checkProperties($paramObj, ['real_name','id_card','kaihuhang','bank_name','province','city','area','bank_num','user_id','bank_code','bank_token']);
        if (!$check) {
            throw new Exception("参数不足", ProfessionErrorCodeEnum::STATUS_ERROR_PARAMS_MUST);
        }

        #是否绑定银行卡
        $bank_info = $this->mBankManage->SelUserBank($user_id);
        if(!$bank_info){
            throw new Exception("请先绑定银行卡",ProfessionErrorCodeEnum::ERROR_BANK_NUM);
        }

        $user_info = $this->mUser->ApiGetUserInfo($user_id);

        #银行卡号验证
        if (!preg_match('/^(\d{16}|\d{19})$/', $paramObj->bank_num)) {
            throw new Exception("银行卡号格式错误",ProfessionErrorCodeEnum::ERROR_BANK_NUM);
        }

        $auth = $this->mLog->BankAuth($paramObj,$user_info->mobile);

        if($auth['error']==0){
            return $auth['message'];
        }else{
            throw new Exception($auth['message'],1);
        }

//        if($user_info->real_name!=$paramObj->real_name){
//            throw new Exception("与登录姓名信息不符", ProfessionErrorCodeEnum::ERROR_NAME_FORMAT);
//        }
//
//        #姓名验证
//        if(!preg_match('/^[\x80-\xff]{4,18}$/',$paramObj->real_name)){
//            throw new Exception("姓名格式错误", ProfessionErrorCodeEnum::ERROR_NAME_FORMAT);
//        }
//
//        #身份证验证
//        if (!preg_match('/^(\d{15}$|^\d{18}$|^\d{17}(\d|X|x))$/', $paramObj->id_card)) {
//            throw new Exception("身份证格式错误",ProfessionErrorCodeEnum::ERROR_ID_CARD_FORMAT);
//        }
//
//        if($user_info->id_card!=$paramObj->id_card){
//            throw new Exception("与登录身份证信息不符", ProfessionErrorCodeEnum::ERROR_ID_CARD_FORMAT);
//        }
//

    }

    /**
     * 银行卡绑定
     * @param $paramObj
     * @return mixed
     * @throws Exception
     */
    public function BankRealBound($paramObj)
    {


        #验证登录
        if (!session_get(UserEnum::USER_INFO_SESSION_KEY))
            throw new Exception('用户未登录！', ErrorCodeEnum::STATUS_ERROR_NOT_LOGIN);
        $user_id = session_get(UserEnum::USER_INFO_USER_ID);
        $user_info = $this->mUser->ApiGetUserInfo($user_id);
        #参数验证
        $check = $this->checkProperties($paramObj, ['verify','real_name','id_card','kaihuhang','bank_name','province','city','area','bank_num','bank_code','bank_token']);
        if (!$check) {
            throw new Exception("参数不足", ProfessionErrorCodeEnum::STATUS_ERROR_PARAMS_MUST);
        }


        #是否绑定银行卡
        $bank_info = $this->mBankManage->SelUserBank($user_id);
        if($bank_info){
            throw new Exception("已经绑定银行卡",ProfessionErrorCodeEnum::ERROR_BANK_NUM);
        }

        #银行卡号验证
        if (!preg_match('/^(\d{16}|\d{19})$/', $paramObj->bank_num)) {
            throw new Exception("银行卡号格式错误",ProfessionErrorCodeEnum::ERROR_BANK_NUM);
        }

        $confirm = $this->mLog->BankConfirm($paramObj,$user_info->mobile);
        if($confirm['error']==1){
            throw new Exception($confirm['message'],1);
        }

        $aData = [
            'province'        =>    $paramObj->province,
            'city'            =>    $paramObj->city,
            'area'            =>    $paramObj->area,
            'bank_name'       =>    $paramObj->bank_name,
            'bank_num'        =>    $paramObj->bank_num,
            'bound_name'      =>    $paramObj->real_name,
            'kaihuhang'       =>    $paramObj->kaihuhang,
            'bank_code'       =>    $paramObj->bank_code,
            'user_id'         =>    $user_id,
            'bound_mobile'    =>    $user_info->mobile,
            'status'          =>    2,
            'created'         =>    time()
        ];

        $bank_bound = $this->mBankManage->insert($aData);
        if($bank_bound){
            $bank_info =  $this->mBankManage->SelUserBank($user_id);
            foreach($bank_info as $k=>$v){
                if($v==''){
                    $arr2[$k] = '';
                }else{
                    $arr2[$k] = $v;
                }
            }

            return $arr2;
        }

    }

    /**
     * 银行卡修改
     * @param $paramObj
     * @return mixed
     * @throws Exception
     */
    public function BankRealUp($paramObj)
    {
        #验证登录
        if (!session_get(UserEnum::USER_INFO_SESSION_KEY))
            throw new Exception('用户未登录！', ErrorCodeEnum::STATUS_ERROR_NOT_LOGIN);
        $user_id = session_get(UserEnum::USER_INFO_USER_ID);
        $user_info = $this->mUser->ApiGetUserInfo($user_id);
        #参数验证
        $check = $this->checkProperties($paramObj, ['verify','real_name','id_card','kaihuhang','bank_name','province','city','area','bank_num','user_id','bank_code','bank_token']);
        if (!$check) {
            throw new Exception("参数不足", ProfessionErrorCodeEnum::STATUS_ERROR_PARAMS_MUST);
        }

        #是否绑定银行卡
        $bank_info = $this->mBankManage->SelUserBank($user_id);
        if(!$bank_info){
            throw new Exception("请先绑定银行卡",ProfessionErrorCodeEnum::ERROR_BANK_NUM);
        }

        #银行卡号验证
        if (!preg_match('/^(\d{16}|\d{19})$/', $paramObj->bank_num)) {
            throw new Exception("银行卡号格式错误",ProfessionErrorCodeEnum::ERROR_BANK_NUM);
        }

        $confirm = $this->mLog->BankConfirm($paramObj,$user_info->mobile);
        if($confirm['error']==1){
            throw new Exception($confirm['message'],1);
        }

        $aData = [
            'province'        =>    $paramObj->province,
            'city'            =>    $paramObj->city,
            'area'            =>    $paramObj->area,
            'bank_name'       =>    $paramObj->bank_name,
            'bank_num'        =>    $paramObj->bank_num,
            'bound_name'      =>    $paramObj->real_name,
            'kaihuhang'       =>    $paramObj->kaihuhang,
            'bank_code'       =>    $paramObj->bank_code,
            'user_id'         =>    $user_id,
            'bound_mobile'    =>    $user_info->mobile,
            'status'          =>    2,
            'created'         =>    time()
        ];

        $bank_up = $this->mBankManage->update($aData,['user_id'=>$paramObj->user_id]);

        if($bank_up){
            $bank_info =  $this->mBankManage->SelUserBank($user_id);
            foreach($bank_info as $k=>$v){
                if($v==''){
                    $arr2[$k] = '';
                }else{
                    $arr2[$k] = $v;
                }
            }

            return $arr2;
        }else{
            throw new Exception("修改失败");
        }

    }

    /**
     * 银行卡删除成功
     * @param $paramObj
     * @return stdClass
     * @throws Exception
     * @author lzhp
     * @date 2016-06-30
     */
    public function BankDel($paramObj)
    {
        #验证登录
        if (!session_get(UserEnum::USER_INFO_SESSION_KEY))
            throw new Exception('用户未登录！', ErrorCodeEnum::STATUS_ERROR_NOT_LOGIN);
        $user_id = session_get(UserEnum::USER_INFO_USER_ID);

        #参数验证
        $check = $this->checkProperties($paramObj, ['pay_pwd','user_id']);
        if (!$check) {
            throw new Exception("参数不足", ProfessionErrorCodeEnum::STATUS_ERROR_PARAMS_MUST);
        }

        $user_info = $this->mUser->ApiGetUserInfoPwd($user_id);

        #支付密码
        if($user_info->pay_pwd!= md5(md5($paramObj->pay_pwd).$user_info->pay_num)){
            throw new Exception("支付密码错误", ProfessionErrorCodeEnum::ERROR_PASSWORD_FAILURE);
        }

        $bank_del = $this->mBankManage->delete(['user_id'=>$paramObj->user_id]);
        if($bank_del){
            return new stdClass();
        }else{
            throw new Exception("删除失败");
        }

    }

    /**
     * 投标记录查询
     * @param $paramObj
     * @return mixed
     * @throws Exception
     * @author lzhp
     * @date 2016-06-30
     */
    public function BidRecord($paramObj)
    {
        #参数验证
        $check = $this->checkProperties($paramObj, ['project_id']);
        if (!$check) {
            throw new Exception("参数不足", ProfessionErrorCodeEnum::STATUS_ERROR_PARAMS_MUST);
        }

        return $this->mInvestRecord->BidRecord($paramObj->page,$paramObj->project_id);

    }

    /**
     * 体验标投标记录
     * @param $paramObj
     * @return mixed
     * @author lzhp
     * @date 2016-07-06
     */
    public function ExperBidRecord($paramObj)
    {
        $exper =  $this->mExperRecord->ExperBidRecord($paramObj->page);
        $arr1 = array();
        foreach($exper as $k=>$v){
            if($v==''){
                $arr1[$k] = '';
            }else{
                $arr1[$k] = $v;
            }
        }
        return $arr1;
    }

    /**
     * 银行卡表
     * @return array
     * @author lzhp
     * @date 2016-07-01
     */
    public function BankCard()
    {
        $bank_card =  $this->mBankCard->BankCard();
        //print_r($bank_card);die;
        $arr = array();
        foreach($bank_card as $k=>$v){
            foreach($v as $kk=>$vv){
                if($v==''){
                    $arr[$k][$kk] = '';
                }else{
                    $arr[$k][$kk] = $vv;
                }
            }
        }
        return $arr;
    }

    /**
     * 银行卡信息返回
     * @return mixed
     * @throws Exception
     * @author lzhp
     * @date 2016-07-05
     */
    public function BankInfo()
    {
        #验证登录
        if (!session_get(UserEnum::USER_INFO_SESSION_KEY))
            throw new Exception('用户未登录！', ErrorCodeEnum::STATUS_ERROR_NOT_LOGIN);
        $user_id = session_get(UserEnum::USER_INFO_USER_ID);

        $bank_info = $this->mBankManage->BankInfo($user_id);
        if($bank_info){
            foreach($bank_info as $k=>$v){
                if($v==''){
                    $arr[$k] = '';
                }else{
                    $arr[$k] = $v;
                }
            }
            return $arr;
        }
        return $bank_info;
    }

    /**
     * 资产日历
     * @param $paramObj
     * @return mixed
     * @throws Exception
     * @author lzhp
     * @date 2016-07-07
     */
    public function Calendar($paramObj)
    {
        #验证登录
        if (!session_get(UserEnum::USER_INFO_SESSION_KEY))
            throw new Exception('用户未登录！', ErrorCodeEnum::STATUS_ERROR_NOT_LOGIN);
        $user_id = session_get(UserEnum::USER_INFO_USER_ID);

        #参数验证
        $check = $this->checkProperties($paramObj, ['year','month','user_id']);
        if (!$check) {
            throw new Exception("参数不足", ProfessionErrorCodeEnum::STATUS_ERROR_PARAMS_MUST);
        }

        $day  = $this->mLineChart->CalendarDay($paramObj->year,$paramObj->month,$paramObj->user_id);
        if($paramObj->day){
            $data  = $this->mLineChart->CalendarD($paramObj->year,$paramObj->month,$paramObj->day,$paramObj->user_id);
        }else{
            $data  = $this->mLineChart->CalendarM($paramObj->year,$paramObj->month,$paramObj->user_id);
        }



        $arr2 = array();
        if($day){
            foreach($day as $k=>$v){
                $v = json_encode($v);
                $v = json_decode($v,true);
                foreach($v as $kk=>$vv){
                    $arr2[] = $vv;
                }
            }
        }else{
            $arr2 = [];
        }

        if($data){
            $arr = array();
            foreach($data as $k=>$v){
                foreach($v as $kk=>$vv){
                    $arr[$kk] = sprintf("%1.2f",$vv);
                }
            }
        }else{
            $arr = [
                 "money" =>sprintf("%1.2f",0),
                 "profit_money" =>sprintf("%1.2f",0),
                 "recharge_money" =>sprintf("%1.2f",0),
                 "withdraw_money" =>sprintf("%1.2f",0)
            ];

        }

        return $aData=[
            'info' => $arr,
            'day'  => $arr2
        ];


    }

    /**
     * 获取个人信息
     * @return mixed
     * @throws Exception
     */
    public function GetUserInfo()
    {
        #验证登录
        if (!session_get(UserEnum::USER_INFO_SESSION_KEY))
            throw new Exception('用户未登录！', ErrorCodeEnum::STATUS_ERROR_NOT_LOGIN);

        $user_id = session_get(UserEnum::USER_INFO_USER_ID);

        $user_info = $this->mUser->ApiGetUserInfo($user_id);
        $bank_info = $this->mBankManage->BankInfo($user_id);

        $arr1 =array();
        if($user_info){
            foreach($user_info as $k=>$v){
                if($v==''){
                    $arr1[$k] = '';
                }else{
                    $arr1[$k] = $v;
                }
            }
        }else{
            $arr1 = new stdClass();
        }

        $arr2 =array();
        if($bank_info){
            foreach($bank_info as $k=>$v){
                if($v==''){
                    $arr2[$k] = '';
                }else{
                    $arr2[$k] = $v;
                }
            }
        }else{
            $arr2 = null;
        }

        return $aData=[
            'user_info' => $arr1,
            'bank_info' => $arr2,
        ];

    }

    /**
     * 首页banner
     * @return mixed
     * @author lzhp
     * @date 2016-07-06
     */
    public function BannerShow(){
        $banner =  $this->mAds->BannerShow();
        $arr = array();
        foreach($banner as $k=>$v){
          $v = json_encode($v);
          $v = json_decode($v,true);
          foreach($v as $kk=>$vv){
              $arr[] = $vv;
          }
        }
        return $arr;

    }

    public function MessageStatus($paramObj)
    {
        #验证登录
        if (!session_get(UserEnum::USER_INFO_SESSION_KEY))
            throw new Exception('用户未登录！', ErrorCodeEnum::STATUS_ERROR_NOT_LOGIN);
//        $user_id = session_get(UserEnum::USER_INFO_USER_ID);

        #参数验证
        $check = $this->checkProperties($paramObj, ['user_id','message_id']);
        if (!$check) {
            throw new Exception("参数不足", ProfessionErrorCodeEnum::STATUS_ERROR_PARAMS_MUST);
        }

        $aData=[
            'status' => 1,
        ];

        $info = $this->mMessage->update($aData,['user_id'=>$paramObj->user_id,'message_id'=>$paramObj->message_id]);
        if($info){
            return new stdClass();
        }else {
            throw new Exception("修改失败");
        }
    }



}